﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MMITDomain.Abstract;
using MMITDomain.Entities;

namespace MMITDomain.Concrete
{
    public class EFAccountRepository : IAccountRepository
    {
        private EFDbContext dbContext = new EFDbContext();

        #region IAccountRepository Members

        public IQueryable<Account> Accounts
        {
            get 
            {
                return dbContext.Accounts;
            }
        }

        public void SaveAccount(Account objAccount)
        {
            if (objAccount.Id == 0)
            {
                dbContext.Accounts.Add(objAccount);
            }

            dbContext.SaveChanges();
        }

        public void DeleteAccount(Account objAccount)
        {
            dbContext.Accounts.Remove(objAccount);
            dbContext.SaveChanges();
        }

        public Account GetAccountById(int iAccountId)
        {
            return dbContext.Accounts.Find(iAccountId);
        }

        public IQueryable<Account> GetCustomerAccounts(Customer objCustomer)
        {
            return dbContext.Accounts.Where(account => account.Customer.Id == objCustomer.Id);
        }

        public Currency GetAccountCurrency(Account objAccount)
        {
            return objAccount.Currency;
            
        }
        #endregion
    }
}
